using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Xml;
using System.IO;
using System.Text.RegularExpressions;

using WPS.Libraries.CssDom;

namespace WPS.Modules.StyleLibrary
{
	/// <summary>
	///  Page for editing TextBox styles (DIV) in the Style Library.
	/// </summary>
	public partial class TextBoxEdit : StyleLibraryBasePage
	{
		/// <summary>
		/// Patterns for searching TextBox styles the CSS file.
		/// </summary>
		private class RuleSelector
		{
			public const string TextBox = "div.{0}";
			public const string Heading = "div.{0} h2";
			public const string Link = "div.{0} a";
			public const string VisitedLink = "div.{0} a:visited";
		}

		#region Page events 

		protected new void Page_Load(object sender, System.EventArgs e)
		{
			this.CmsIntegration = new StyleLibraryIntegration();
			this.RemoveEmptyRules = true;

			base.Page_Load(sender, e);
		}

		#endregion

		#region Private helper methods

		/// <summary>
		/// Returns an array of StyleRuleSearch objects, with initialized for related selectors.
		/// </summary>
		/// <param name="styleName">Style name to create search rules for.</param>
		/// <returns>StyleRuleSearch array with SelectorText values set for the required css rules.</returns>
		protected override StyleRuleSearch[] GetRules(string styleName)
		{
			return new StyleRuleSearch[] {
				new StyleRuleSearch(String.Format(RuleSelector.TextBox, styleName)), 
				new StyleRuleSearch(String.Format(RuleSelector.Heading, styleName)), 
				new StyleRuleSearch(String.Format(RuleSelector.Link, styleName)),
				new StyleRuleSearch(String.Format(RuleSelector.VisitedLink, styleName))
			};
		}

		/// <summary>
		/// Return an array of selector strings with a new name.
		/// </summary>
		/// <param name="newName">New style name for selectors.</param>
		/// <returns>List of CSS selectors necessary for this style.</returns>
		protected override string[] GetRenames(string newName)
		{
			string[] renames = {
					String.Format(RuleSelector.TextBox, newName), 
					String.Format(RuleSelector.Heading, newName),
					String.Format(RuleSelector.Link, newName),
					String.Format(RuleSelector.VisitedLink, newName) 
			};
			return renames;

		}

		/// <summary>
		/// Interface function from superclasses to our PageMessageControl.
		/// </summary>
		/// <param name="message">Message to send.</param>
		/// <param name="type">Message type.</param>
		protected override void SendPageMessage(string message, bool error)
		{
			pgmPageMessage.Send(message, error);
		}

		#endregion

		#region Child control init

		protected void btnSave_Init(object sender, EventArgs e)
		{
			btnSave.Attributes.Add("onclick", "updateDemo(); return true;");
		}

		#endregion
	}
}
